package com.zhijian.medical.controller;

import com.zhijian.medical.annotation.Response;
import com.zhijian.medical.entity.vo.request.ExperimentProcessSampleReadySaveOrUpdateOutVo;
import com.zhijian.medical.entity.vo.request.ExperimentProcessSampleReadySearchVo;
import com.zhijian.medical.entity.vo.request.SampleReadySaveOrUpdateVo;
import com.zhijian.medical.entity.vo.response.ExperimentProcessSampleReadyListVo;
import com.zhijian.medical.entity.vo.response.ExperimentProcessSampleReadyVo;
import com.zhijian.medical.entity.vo.response.ExperimentProcessSampleVo;
import com.zhijian.medical.service.ExperimentProcessSampleReadyService;
import com.zhijian.medical.service.ExperimentProcessSampleService;
import com.zhijian.medical.util.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 样本准确（RNA/DNA）
 *
 * @author HCG
 * @version 1.0
 * @date 2022-08-19 14:17:13
 */
@Slf4j
@Controller
@Api(tags = "样本准备（RNA/DNA）")
public class SampleReadyController {

    @Autowired
    private ExperimentProcessSampleReadyService service;

    @Autowired
    private ExperimentProcessSampleService experimentProcessSampleService;

    /**
     * 实验里保存
     *
     * @param param
     * @return
     */
    @Response
    @PutMapping("/sample/ready/in/{id}")
    @ApiOperation("实验里保存")
    public boolean insert(@PathVariable("id") Long id, @RequestBody ExperimentProcessSampleReadySaveOrUpdateOutVo param) {
        param.setId(id);
        log.info("{} - {}| insert info", this.getClass().getSimpleName(), param);
        return service.saveDetail(param);
    }

    /**
     * 添加实验
     *
     * @param param
     * @return
     */
    @Response
    @PostMapping("/sample/ready")
    @ApiOperation("添加实验")
    public boolean insert(@RequestBody SampleReadySaveOrUpdateVo param) {
        log.info("{} - {}| insert info", this.getClass().getSimpleName(), param);
        return service.save(param);
    }

    /**
     * 根据RNA或者DNA或者FISH查询要样本准备的样本列表
     *
     * @param drType
     * @return
     */
    @Response
    @GetMapping("/sample/ready/list/{drType}")
    @ApiOperation("根据RNA或者DNA或者FISH查询要样本准备的样本列表")
    public List<ExperimentProcessSampleVo> selectWaitReady(@ApiParam(name = "drType", value = "RNA(0)，DNA(1)，FISH(2)")
                                                           @PathVariable("drType") Integer drType) {
        return experimentProcessSampleService.selectWaitReady(drType);
    }

    /**
     * 修改
     *
     * @param id
     * @param param
     * @return
     */
    @Response
    @PutMapping("/sample/ready/{id}")
    @ApiOperation("修改")
    public boolean update(@PathVariable("id") Long id, @RequestBody SampleReadySaveOrUpdateVo param) {
        log.info("{} - {}| update info, {}", this.getClass().getSimpleName(), id, param);
        param.setId(id);
        return service.update(param);
    }

    /**
     * 进入实验的详情接口
     *
     * @param id
     * @return
     */
    @Response
    @GetMapping("/sample/ready/in/{id}")
    @ApiOperation("进入实验的详情接口")
    public ExperimentProcessSampleReadyVo selectVoById(@PathVariable("id") Long id) {
        log.info("{} - {}| query info", this.getClass().getSimpleName(), id);
        return service.selectVoById(id);
    }

    /**
     * 点击详情查询
     *
     * @param id
     * @return
     */
    @Response
    @GetMapping("/sample/ready/out/{id}")
    @ApiOperation("点击详情查询")
    public ExperimentProcessSampleReadyListVo selectListVoById(@PathVariable("id") Long id) {
        log.info("{} - {}| query info", this.getClass().getSimpleName(), id);
        return service.selectListVoById(id);
    }

    /**
     * 分页查询
     *
     * @param param
     * @return
     */
    @Response
    @PostMapping("/sample/ready/page")
    @ApiOperation("分页查询")
    public Page<ExperimentProcessSampleReadyListVo> selectByCondition(@RequestBody(required = false) ExperimentProcessSampleReadySearchVo param) {
        if (param == null)
            param = ExperimentProcessSampleReadySearchVo.builder().build();
        log.info("{} - {}| query info", this.getClass().getSimpleName(), param);
        return service.selectPage(param);
    }

}